﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using ERP_RORZE_ORDER.BizLogic;
using ERP_RORZE_ORDER.Common.ValueObject;
using ERP_RORZE_TOOL.Common;

namespace ERP_RORZE_ORDER.OrderObject.UserControls
{
    public partial class ucProduct : DevExpress.XtraEditors.XtraUserControl
    {
        private int index = 0;
        public int _action = 1;
        DXPopupMenu menu;

        #region Handle methods
        public ucProduct()
        {
            InitializeComponent();
            InitPopupMenu();

            BindDatatoGrid();
            gridView1.BestFitColumns();
            this.dropbtExport.DropDownControl = menu;
        }

        private void btDelete_Click(object sender, EventArgs e)
        {

        }

        private void btEdit_Click(object sender, EventArgs e)
        {

        }

        private void btAddNew_Click(object sender, EventArgs e)
        {

        }

        private void btRefresh_Click(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {

        }

        private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
        {

        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {

        }

        private void addNewToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void gridControl1_ProcessGridKey(object sender, KeyEventArgs e)
        {

        }
        #endregion


        #region Private methods
        public void BindDatatoGrid()
        {
            ProductHelper helper = new ProductHelper(new Product());
            DataTable dt = helper.GetAll();

            gridControl1.DataSource = dt;
            Utilities.GridUtil.SelectRow(gridView1, index, _action);
        }


        protected virtual void InitPopupMenu()
        {
            menu = new DXPopupMenu();
            menu.Items.Add(new DXMenuItem("Export all", new EventHandler(OnItemClickExportAll), null, null, null, null));
            menu.Items.Add(new DXMenuItem("Export selected row(s)", new EventHandler(OnItemClickExportRows), null, null, null, null));

        }
        void OnItemClickExportAll(object sender, EventArgs e)
        {
            Utilities.ExportToExcel(gridView1, 1, true);
        }
        void OnItemClickExportRows(object sender, EventArgs e)
        {
            Utilities.ExportToExcel(gridView1, 0, true);
        }

        private void AddNew()
        {
            Cursor.Current = Cursors.WaitCursor;
            //Form fr = new frm_ToolAdd(this);
            //fr.StartPosition = FormStartPosition.CenterParent;
            //fr.ShowDialog();
            Cursor.Current = Cursors.Default;

        }

        #endregion


    }
}
